package com.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

/**
 * @author admin
 */
    //@WebFilter(filterName = "EncodingFilter",urlPatterns = "/EncodingFilter",initParams = {@WebInitParam(name="encoding",value="UTF-8")})
public class EncodingFilter implements Filter {
    //编码过滤

    private  String encoding;

    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
//        System.out.println(encoding);
        req.setCharacterEncoding(encoding);
        chain.doFilter(req, resp);
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
        encoding = config.getInitParameter("encoding");
    }

}
